<?php 
## include required files
/*******************************/
require_once '../model/budget.php';
/*******************************/
## Create Objects
/*******************************/
$budgetObj = new Model_Budget();
/*******************************/

if(isset($_POST['addbudget_btn'])) {	
	## apply PHP validation for required filed
	
	if(trim($_POST['budgetname']) != '') 
	{
		if($_POST['budgetfrom'] < $_POST['budgetto'])
		{
			$budgetAddArray['budget_name']      = $_POST['budgetname'];
			$budgetAddArray['budgetfrom']   = return_post_value($_POST['budgetfrom']);		
			$budgetAddArray['budgetto']   = return_post_value($_POST['budgetto']);		
	
			$budgetAddArray['budget_status']      = '1';
			$budgetObj->addBudget($budgetAddArray);
			$_SESSION['msg'] = "<div class='success_msg'><span>Budget added successfully</span></div>";
			header('location:'.SITE_URL.'/admin/home.php?q=budget&page='.$_POST['page']);
			exit;
		}
		else
			$_SESSION['msg'] = '<div class="error_msg"><span>Please enter budget range to greater than budget range from</span></div>';
	} 
	else 
	{
		$_SESSION['msg'] = '<div class="error_msg"><span>Please fill all required fields</span></div>';
	}
	// main if closed
}


## Assign success or error msg to smarty variable and unset session variable
if(trim($_SESSION['msg']) != '') {
	$smarty->assign('msg', $_SESSION['msg']);
	unset($_SESSION['msg']);
}

## Set active class variable for left menu
$smarty->assign('activeclass', 'budget');
$smarty->assign('mainmenu', '2');
## Unset all the objects created which are on this page

unset($budgetObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'budget/addbudget.tpl');
unset($smarty);
?>